<?php
/**
 * 
 * @author Freezy
 *
 */
class Login extends MY_Controller {
	function Login(){
		parent::MY_Controller ();
	}

	function _check(){
		$this->load->model('login_model');
		$usrname = $this->input->post('username');
		$password = $this->input->post('password');
		
		$res = $this->login_model->authenticate($usrname, md5($password));
		
		echo json_encode(array('error'=>!$res,
			'msg'=>$res? "" : "Kombinasi Username dan Password salah",

			'url'=>$res? $this->_initialize_page($usrname) : ""));
	}
	
	function _initialize_page($usrname){
		$this->load->library('session');
		$this->session->set_userdata('logged', true);
		$this->session->set_userdata('usrname', $usrname);
		
		//admin
		if ($this->login_model->getLevel($usrname) == -1){
			return site_url(array('psdm','dashboard'));
		}
		else if($this->login_model->getLevel($usrname) > 0){
			return site_url(array('users',md5($usrname),'dashboard'));
		}
		return "";
	}
	
	function out(){
		$this->load->library('session');
		$this->session->sess_destroy();
		redirect('','location', 301);
	}
}
/* End of file auth.php */
/* Location: ./system/application/controllers/auth.php */